import java.util.ArrayList;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 晓星航
 * Date: 2023-12-10
 * Time: 16:02
 */
//动态规划
public class YanghuiTriangle2 {
    public static void main(String[] args) {
        int numRows = 5; // 杨辉三角的行数

        List<List<Integer>> triangle = new ArrayList<>();

        for (int i = 0; i < numRows; i++) {
            List<Integer> row = new ArrayList<>();
            row.add(1);

            for (int j = 1; j < i; j++) {
                List<Integer> prevRow = triangle.get(i-1);
                int num = prevRow.get(j-1) + prevRow.get(j);
                row.add(num);
            }

            if (i > 0) {
                row.add(1);
            }

            triangle.add(row);
        }

        // 打印杨辉三角
        for (List<Integer> row : triangle) {
            for (int num : row) {
                System.out.print(num + " ");
            }
            System.out.println();
        }
    }
}
